<?php

/**
52zll.top
 */

if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}

$activity = C::t('#dzapp_zhibo#dzapp_zhibo_activity')->fetch($_GET['activity_id']);

$lang = array_merge($lang, $scriptlang['dzapp_zhibo']);
require_once libfile('function/base', 'plugin/dzapp_base');

if(empty($_GET['ac'])) {

	if(!submitcheck('listsubmit')) {

		showformheader('plugins&operation=config&identifier=dzapp_zhibo&pmod=admincp_graphic');
		showtableheader();
		showsubtitle(array('del', 'name', 'url', ''));
		$perpage = 20;
		$start = ($page - 1) * $perpage;
		$mpurl = ADMINSCRIPT."?action=plugins&operation=config&identifier=dzapp_zhibo&pmod=admincp_graphic";
		$param = array(
			array('activity_id', $_GET['activity_id']),
		);
		$count = C::t('#dzapp_zhibo#dzapp_zhibo_graphic')->count_by_search($param);
		if($count) {
			$query = C::t('#dzapp_zhibo#dzapp_zhibo_graphic')->fetch_all_by_search($param, $start, $perpage);
			foreach($query as $value) {
				showtablerow('', array('class="td25"'), array(
					'<input type="checkbox" class="checkbox" name="delete[]" value="'.$value['graphic_id'].'" />',
					$value['name'],
					$value['url'],
					'<a href="'.ADMINSCRIPT.'?action=plugins&operation=config&identifier=dzapp_zhibo&pmod=admincp_graphic&ac=edit&id='.$value['graphic_id'].'">'.cplang('edit').'</a>'
				));
			}
			$multipage = multi($count, $perpage, $page, $mpurl);
		}
		echo '<tr><td></td><td colspan="20"><div><a href="'.ADMINSCRIPT.'?action=plugins&operation=config&identifier=dzapp_zhibo&pmod=admincp_graphic&ac=add&activity_id='.$_GET['activity_id'].'" class="addtr">'.cplang('add_graphic').'</a></div></td></tr>';
		showsubmit('listsubmit', 'submit', 'del', '', $multipage);
		showtablefooter();
		showformfooter();

	} else {

		if(is_array($_GET['delete'])) {
			C::t('#dzapp_zhibo#dzapp_zhibo_graphic')->delete($_GET['delete']);
		}

		cpmsg('graphic_update_succeed', 'action=plugins&operation=config&identifier=dzapp_zhibo&pmod=admincp_graphic&activity_id='.$_GET['activity_id'], 'succeed');
	}

} elseif($_GET['ac'] == 'add') {
	
	if(!submitcheck('addsubmit')) {

		showformheader('plugins&operation=config&identifier=dzapp_zhibo&pmod=admincp_graphic&ac=add&activity_id='.$_GET['activity_id'], 'enctype');
		showtableheader();
		showsetting('pic', 'pic', '', 'filetext');
		showsetting('video_url', 'video_url', '', 'text');
		showsetting('name', 'name', '', 'text');
		showsetting('describe', 'describe', '', 'textarea');
		showsetting('url', 'url', '', 'text');
		showsubmit('addsubmit', 'submit'); 
		showtablefooter();
		showformfooter();

	} else {

		if(!$_GET['name']) {
			cpmsg('graphic_invalid', '', 'error');
		}
		
		if($pic = dzapp_pic_upload($_FILES['pic'], 'portal', 320, 240)) $_GET['pic'] = $pic['pic'];
		$data = array(
			'activity_id' => $_GET['activity_id'],
			'pic' => $_GET['pic'],
			'video_url' => $_GET['video_url'],
			'name' => $_GET['name'],
			'describe' => $_GET['describe'],
			'url' => $_GET['url'],
			'dateline' => $_G['timestamp'],
			'ip' => $_G['clientip'],
		);
		C::t('#dzapp_zhibo#dzapp_zhibo_graphic')->insert($data);

		cpmsg('graphic_add_succeed', 'action=plugins&operation=config&identifier=dzapp_zhibo&pmod=admincp_graphic', 'succeed');
	}

} elseif($_GET['ac'] == 'edit') {

	$graphic = C::t('#dzapp_zhibo#dzapp_zhibo_graphic')->fetch($_GET['id']);
	if(empty($graphic)) {
		cpmsg('graphic_nonexistence', '', 'error');
	}
	
	if(!submitcheck('editsubmit')) {

		showformheader('plugins&operation=config&identifier=dzapp_zhibo&pmod=admincp_graphic&ac=edit&id='.$graphic['graphic_id'], 'enctype');
		showtableheader();
		showsetting('pic', 'pic', $graphic['pic'], 'filetext');
		showsetting('video_url', 'video_url', $graphic['video_url'], 'text');
		showsetting('name', 'name', $graphic['name'], 'text');
		showsetting('describe', 'describe', $graphic['describe'], 'textarea');
		showsetting('url', 'url', $graphic['url'], 'text');
		showsubmit('editsubmit', 'submit'); 
		showtablefooter();
		showformfooter();

	} else {

		if(!$_GET['name']) {
			cpmsg('graphic_invalid', '', 'error');
		}
		
		if($pic = dzapp_pic_upload($_FILES['pic'], 'portal', 320, 240)) $_GET['pic'] = $pic['pic'];
		if($pic && $graphic['pic']) dzapp_pic_delete($graphic['pic'], 'portal', 1);
		$data = array(
			'pic' => $_GET['pic'],
			'video_url' => $_GET['video_url'],
			'name' => $_GET['name'],
			'describe' => $_GET['describe'],
			'url' => $_GET['url'],
		);
		C::t('#dzapp_zhibo#dzapp_zhibo_graphic')->update($graphic['graphic_id'], $data);

		cpmsg('graphic_edit_succeed', 'action=plugins&operation=config&identifier=dzapp_zhibo&pmod=admincp_graphic', 'succeed');
	}
}
//From:www_caogen8_co
?>